﻿using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Identity;

namespace Acme.BookStore.Identity
{
    public class IdentityUserAppService : Volo.Abp.Identity.IdentityUserAppService, IIdentityUserAppService
    {
        public IdentityUserAppService(
            IdentityUserManager userManager,
            IIdentityUserRepository userRepository,
            IIdentityRoleRepository roleRepository,
            IOptions<IdentityOptions> identityOptions) : base(userManager, userRepository, roleRepository, identityOptions)
        {
        }

        public async Task<PagedResultDto<IdentityUserAndRoleDto>> GetListAndRoleAsync(GetIdentityUsersInput input)
        {
            var datas = await base.GetListAsync(input);
            var resultDatas = new List<IdentityUserAndRoleDto>();
            foreach (var data in datas.Items)
            {
                var rd = ObjectMapper.Map<Volo.Abp.Identity.IdentityUserDto, IdentityUserAndRoleDto>(data);
                rd.RoleNames = await UserRepository.GetRoleNamesAsync(data.Id);
                resultDatas.Add(rd);
            }
            return new PagedResultDto<IdentityUserAndRoleDto>(datas.TotalCount, resultDatas);
        }

    }
}
